package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class Test3 {
    public static void main(String[] args) {
        Article article = InputUtil.getInputObject(new Article(),"请输入标题和正文");
        try {
            Connection connection = DBUtil.getConnection();
            Scanner sc = new Scanner(System.in);
            String sql = "INSERT INTO article(title, content) VALUES (?,?)";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1,article.getTitle());
            ps.setString(2,article.getContent());
            int num = ps.executeUpdate();
            if(num > 0){
                System.out.println("插入成功");
            }else{
                System.out.println("插入失败");
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
